﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using STLGROUP.Layers.Presentations.FormBase;
using STLGROUP.Layers.Common;

namespace QuanLyBanHang
{
    /// <summary>
    /// CF009 Khuyen Mai - Giam Gia Hoa Don
    /// </summary>
    public partial class CF009 : frmCatalogBase
    {
        #region Constructors

        public CF009()
        {
            InitializeComponent();
            this.btnChuongTrinhKM.Click += new EventHandler(btnChuongTrinhKM_Click);
        }

        #endregion

        #region Protected Methods

        protected override void LoadData()
        {
            this._bindingSource.DataSource = Cache.Context.KM_GiamGiaHoaDon;
            dgvGiamGiaHoaDon.DataSource = _bindingSource;

            base.LoadData();
        }

        protected override void AddDataBinding()
        {
            txtGiaTriToiThieu.DataBindings.Add(Const.BIND_TEXT, _bindingSource, "GiaTriToiThieu", true);
            txtHeSo.DataBindings.Add(Const.BIND_VALUE, _bindingSource, "HeSoGiamGia", true);           

            cboChuongTrinhKM.DataSource = Cache.Context.KM_ChuongTrinhKhuyenMai;
            cboChuongTrinhKM.ValueMember = "IDChuongTrinhKM";
            cboChuongTrinhKM.DisplayMember = "TenChuongTrinh";
            cboChuongTrinhKM.DataBindings.Add(Const.BIND_SELECTED_VALUE, _bindingSource, "IDChuongTrinhKM", true);

            colChuongTrinhKhuyenMai.DataSource = Cache.Context.KM_ChuongTrinhKhuyenMai;
            colChuongTrinhKhuyenMai.ValueMember = "IDChuongTrinhKM";
            colChuongTrinhKhuyenMai.DisplayMember = "TenChuongTrinh";

            base.AddDataBinding();
        }

        protected override void AddNew()
        {
            base.AddNew();
            cboChuongTrinhKM.Focus();
        }

        #endregion

        #region Events

        private void dgvGiamGiaHoaDon_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }

        private void btnChuongTrinhKM_Click(object sender, EventArgs e)
        {
            UICommon.ShowPopup(new CF008(), StructsEnums.EnumDanhMuc.ChuongTrinhKhuyenMai, cboChuongTrinhKM, colChuongTrinhKhuyenMai);
        }

        #endregion

    }
}
